﻿using Aspose.Words;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace AsposeWord模板多行打印
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document("Moduel\\AsposeWord多行打印模板.docx");

            //建立数据源
            DataTable dt = new DataTable("UserList");
            dt.Columns.Add("ID", typeof(int));
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Sexy", typeof(string));
            dt.Columns.Add("Age", typeof(string));
            dt.Columns.Add("WorkID", typeof(string));

            //写入数据
            dt.Rows.Add(1,"Shawn","男","23","22326");
            dt.Rows.Add(1,"Shawn","男","23","22326");
            dt.Rows.Add(1,"Shawn","男","23","22326");
            dt.Rows.Add(1,"Shawn","男","23","22326");
            dt.Rows.Add(1,"Shawn","男","23","22326");

            //载入数据源
            doc.MailMerge.ExecuteWithRegions(dt);

            doc.Save("导出模板.docx", SaveFormat.Docx);
        }
    }
}
